// pages/index/index.js
let cdn = 'https://www.linqinghu.cn/ruixiang';
import {ajax} from "../../utils/httpRequest.js";
import {URI_GETSMALLHOUSELIST} from "../../api.js";

Page({

  /**
   * 页面的初始数据
   */
  data: {
    selectList: ['二手房', '租房', '新房'],
    selectedIndex: 0,
    hidden: true,
    tenModule: [
      {icon: cdn + '/static/img/index/index01.png', title: '二手房', toUrl: '/pages/houseList/houseList?label=0'},
      {icon: cdn + '/static/img/index/index02.png', title: '租房', toUrl: '/pages/houseList/houseList?label=1'},
      {icon: cdn + '/static/img/index/index07.png', title: '新楼盘', toUrl: '/pages/houseList/houseList?label=2'},
      {
        icon: cdn + '/static/img/index/index08.png',
        title: '贷款计算',
        toUrl: "/pages/webview/webview"
      },
    ],
    bannerList: [
      cdn + '/static/img/index/ad1.jpg', cdn + '/static/img/index/ad2.png', cdn + '/static/img/index/ad3.jpg'
    ],
    houseList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getSmallHouseList();
  },

  getSmallHouseList() {
    ajax.get(URI_GETSMALLHOUSELIST, {
      type: 1
    }, {}, res => {
      this.setData({
        houseList: res.data
      })
    })
  },
  toggleShowSelect() {
    this.setData({
      hidden: !this.data.hidden
    })
  },
  selectClick(e) {
    // e.target.
    let index = e.currentTarget.dataset.index;
    this.setData({
      selectedIndex: index,
      hidden: true
    })
  },
  toSearch() {
    wx.navigateTo({
      url: '/pages/search/search?label=' + this.data.selectedIndex
    })
  },
  toMore(){
    wx.navigateTo({
      url:'/pages/houseList/houseList?label=0'
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})